import request from '@/utils/request';
import type { BuildingVO, BuildingQuery, BuildingForm, DistrictVO, BuildingPhotoVO } from './types';
import { AxiosPromise } from 'axios';

// 查询片区列表
export const listDistrict = (query: any) => {
  return request({
    url: '/park/district/list',
    method: 'get',
    params: query
  });
};

// 新增片区
export const addDistrict = (data: any) => {
  return request({
    url: '/park/district/add',
    method: 'post',
    data: data
  });
};

// 修改片区
export const updateDistrict = (data: any) => {
  return request({
    url: '/park/district/edit',
    method: 'post',
    data: data
  });
};

// 删除片区
export const removeDistrict = (data: any) => {
  return request({
    url: '/park/district/remove/' + data,
    method: 'post',
    data: data
  });
};



// 查询楼宇列表
export const getBuildingList = (data: any) => {
  return request({
    url: `/park/housing/list`,
    method: 'get',
    params: data
  });
};

// 新增楼宇
export const addBuilding = (data: any) => {
  return request({
    url: '/park/housing/add',
    method: 'post',
    data: data
  });
};

// 修改楼宇
export const updateBuilding = (data: any) => {
  return request({
    url: '/park/housing/edit',
    method: 'post',
    data: data
  });
};

// 删除楼宇
export const delBuilding = (ids: any) => {
  return request({
    url: `/park/housing/remove/${ids}`,
    method: 'post'
  });
};

// 获取片区列表
export const getDistrictList = () => {
  return request({
    url: '/system/district/list',
    method: 'get'
  });
};

// 查询楼宇照片列表
export const listBuildingPhotos = (buildingId: string) => {
  return request({
    url: `/system/building/photos/${buildingId}`,
    method: 'get'
  });
};

// 上传楼宇照片
export const uploadBuildingPhoto = (data: FormData) => {
  return request({
    url: '/system/building/photo/upload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

// 下载楼宇照片
export const downloadImage = (filePath: string) => {
  return request({
    url: '/park/housing/downloadImage/' + filePath,
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    responseType: 'blob'
  });
}
// 设置主图
export const setMainPhoto = (photoId: string, buildingId: string) => {
  return request({
    url: '/system/building/photo/main',
    method: 'put',
    data: { photoId, buildingId }
  });
};

// 删除楼宇照片
export const deleteBuildingPhoto = (photoId: string) => {
  return request({
    url: `/system/building/photo/${photoId}`,
    method: 'post'
  });
};

// 更新照片排序
export const updatePhotoSort = (photos: BuildingPhotoVO[]) => {
  return request({
    url: '/system/building/photo/sort',
    method: 'put',
    data: photos
  });
};

// 更新照片名称
export const updatePhotoName = (photoId: string, photoName: string) => {
  return request({
    url: `/system/building/photo/${photoId}/name`,
    method: 'put',
    data: { photoName }
  });
};


// 查询租户列表
export const listHousingDetails = (query: any) => {
  return request({
    url: '/park/housingDetails/list',
    method: 'get',
    params: query
  });
};

// 新增楼宇详情
export const addHousingDetails = (data: any) => {
  return request({
    url: '/park/housingDetails/add',
    method: 'post',
    data: data
  });
};

// 修改楼宇详情
export const updateHousingDetails = (data: any) => {
  return request({
    url: '/park/housingDetails/edit',
    method: 'post',
    data: data
  });
};

// 删除楼宇详情
export const removeHousingDetails = (data: any) => {
  return request({
    url: '/park/housingDetails/remove/' + data,
    method: 'post',
    data: data
  });
};


// 查询租户列表
export const listTenant = (query: any) => {
  return request({
    url: '/park/tenant/list',
    method: 'get',
    params: query
  });
};

// 新增租户
export const addTenant = (data: any) => {
  return request({
    url: '/park/tenant/add',
    method: 'post',
    data: data
  });
};

// 修改租户
export const updateTenant = (data: any) => {
  return request({
    url: '/park/tenant/edit',
    method: 'post',
    data: data
  });
};

// 删除租户
export const removeTenant = (data: any) => {
  return request({
    url: '/park/tenant/remove/' + data,
    method: 'post',
    data: data
  });
};


// 查询合同列表
export const listContract = (query: any) => {
  return request({
    url: '/park/contract/list',
    method: 'get',
    params: query
  });
};

// 新增合同
export const addContract = (data: any) => {
  return request({
    url: '/park/contract/add',
    method: 'post',
    data: data
  });
};

// 修改合同
export const updateContract = (data: any) => {
  return request({
    url: '/park/contract/edit',
    method: 'post',
    data: data
  });
};

// 删除合同
export const removeContract = (data: any) => {
  return request({
    url: '/park/contract/remove/' + data,
    method: 'post',
    data: data
  });
};

// 租户套餐状态修改
export function checkOutContract(data: any) {
  return request({
    url: '/park/contract/checkOut',
    method: 'post',
    data: data
  });
}

// 查询楼宇详情
export const getHouseingId = (query: any) => {
  return request({
    url: '/park/housing/' + query,
    method: 'get',
    params: query
  });
};

// 查询合同详情
export const getContantId = (query: any) => {
  return request({
    url: '/park/contract/' + query,
    method: 'get',
    params: query
  });
};


// 房源数据分析-查询各片区出租率
export const districtOccupancyRate = (query: any) => {
  return request({
    url: '/park/statistics/districtOccupancyRate',
    method: 'post',
    data: query
  });
};

// 房源数据分析-查询楼宇详情
export const housingOccupancyRate = (query: any) => {
  return request({
    url: '/park/statistics/housingOccupancyRate',
    method: 'post',
    data: query
  });
};

//房源数据分析- 查询楼宇详情
export const leasingTrends = (query: any) => {
  return request({
    url: '/park/statistics/leasingTrends',
    method: 'post',
    data: query
  });
};

//房源数据分析- 总体统计
export const overallStatistics = (query: any) => {
  return request({
    url: '/park/statistics/overallStatistics',
    method: 'post',
    data: query
  });
};

//房源数据分析- 片区统计
export const districtStatistics = (query: any) => {
  return request({
    url: '/park/statistics/districtStatistics',
    method: 'post',
    data: query
  });
};

//房源数据分析- 楼宇统计
export const housingStatistics = (query: any) => {
  return request({
    url: '/park/statistics/housingStatistics',
    method: 'post',
    data: query
  });
};

//房源数据分析- 获取房源表列表
export const housingList = (query: any) => {
  return request({
    url: '/park/statistics/housingList',
    method: 'get',
    params: query
  });
};
//房源详情楼层数据
export const getHousingDetails = (query: any) => {
  return request({
    url: '/park/housing/getDetails',
    method: 'get',
    params: query
  });
};


export const getParkFloor = (query: any) => {
  return request({
    url: '/park/housingDetails/getParkFloor',
    method: 'get',
    params: query
  });
};